//
//  StatusPhotoImageView.swift
//  SinaWeibo
//
//  Created by 郭平 on 15/10/19.
//  Copyright © 2015年 郭平. All rights reserved.
//

import UIKit

class StatusPhotoImageView: UIImageView {

    private var gifImageView: UIImageView?
    
    // 判断是否是gif图片
    var thumbnail_pic: String? {
        
        didSet{
            
            if let picUrl = thumbnail_pic {
                
                sd_setImageWithURL(NSURL(string: picUrl), placeholderImage: UIImage(named: "timeline_image_placeholder"))
                if picUrl.hasSuffix(".gif") {
                    gifImageView?.hidden = false
                }else{
                    gifImageView?.hidden = true
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentMode = UIViewContentMode.ScaleAspectFill
        clipsToBounds = true
        
        let gifImageView = UIImageView(image: UIImage(named: "timeline_image_gif"))
        self.gifImageView = gifImageView
        
        addSubview(gifImageView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.gifImageView!.x = width - self.gifImageView!.width
        self.gifImageView!.y = height - self.gifImageView!.height
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
